//
// Created by chizuru on 2025/9/16.
//

#pragma once
#include <variant>
#include <string>

struct CommandId {
    std::variant<std::string, uint16_t, int64_t, uint8_t> v;

    CommandId() = default;
    CommandId(std::string s) : v(std::move(s)) {}
    CommandId(const char* s) : v(std::string(s)) {}
    CommandId(uint16_t id) : v(id) {}

    CommandId(uint8_t id) : v(id) {}
    template<typename E, typename = std::enable_if_t<std::is_enum_v<E>>>
    CommandId(E e) : v(static_cast<int64_t>(e)) {}

    bool operator==(const CommandId& o) const noexcept { return v == o.v; }

    std::string toString() const {
        return std::visit([](auto&& x) -> std::string {
            using T = std::decay_t<decltype(x)>;
            if constexpr (std::is_same_v<T, std::string>)
                return x;
            else if constexpr (std::is_same_v<T, uint16_t>)
                return std::to_string(x);
            else
                return std::to_string(x); // int64_t case
        }, v);
    }
};
